<?php

	// TITLE: Person_title AUTO MODEL
	// FILE: scaffolding/model/person_title.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createPersonTitle = function($con, $personTitle) {
		$sql = 'INSERT INTO person_title (id, title, description) VALUES (';
		$sql .= $person_title->getId() . ', ';
		$sql .= $person_title->getTitle() . ', ';
		$sql .= $person_title->getDescription() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readPersonTitle = function($con, $id) {
		$sql = 'SELECT * FROM person_title WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$personTitle = new PersonTitle();
			$personTitle->setId(result[0]);
			$personTitle->setTitle(result[1]);
			$personTitle->setDescription(result[2]);
		} else {
			$personTitle = false;
		}
		return $personTitle;
	};

	$updatePersonTitle = function($con, $personTitle) {
		$sql = 'UPDATE person_title SET ';
		$sql .= 'id = ' . $person_title->getId() . ', ';
		$sql .= 'title = ' . $person_title->getTitle() . ', ';
		$sql .= 'description = ' . $person_title->getDescription() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deletePersonTitle = function($con, $id) {
		$sql = 'DELETE FROM person_title WHERE id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listPersonTitle = function($con) {
		$sql = 'SELECT * FROM person_title';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$personTitles = array();
			while ($result = mysqli_fetch_array($results)) {
				$personTitle = new PersonTitle();
				$personTitle->setId(result[0]);
				$personTitle->setTitle(result[1]);
				$personTitle->setDescription(result[2]);
				$personTitles[] = personTitle;
			}// end while
		} else {
			$personTitles = false;
		}
		return $personTitles;
	};

